varying mediump vec3    vertex;
varying lowp    float   fDiffuse;
varying lowp    vec3    fFogIntensity;

uniform mediump float waterAltitude;

const lowp vec3 color_green = vec3(0.738, 0.96, 0.42);
const lowp vec3 color_yellow = vec3(0.718, 0.60, 0.41);

const lowp vec3 color_fog = vec3(1.0,1.0,1.0);

lowp float getCartoonShadingColor (lowp float intensity)
{
    if (intensity<0.1) {
        return 0.1;
    }else if  (intensity<0.2) {
        return 0.2;
    }else if (intensity<0.4) {
        return 0.4;
    }else if (intensity<0.6) {
        return 0.6;
    }else if (intensity<0.8) {
        return 0.8;
    }else if (intensity<1.0) {
        return 1.0;
    }
	
    return 0.6;
}

void main (void)
{
    // under water
    lowp vec3 color = color_green;
    if (vertex.y < waterAltitude) {
        color = color_yellow;
    }

    // light
    lowp float f = fDiffuse*fDiffuse;
    if (f<0.6) {
        f = 0.6;
    }
    
    // fog
    color = color_fog * (1.0-fFogIntensity) + getCartoonShadingColor(f) * color * f * fFogIntensity;
    //color = getCartoonShadingColor(fDiffuse) * f;
    //color = mix(color_fog, color, fFogIntensity);
    
    gl_FragColor = vec4(color, 1.0);
}